//
//  ETMyShopEditController.m
//  etaoLocal
//
//  Created by 稳 张 on 12-5-15.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "smPhotoEditController.h"
#import "GetPhotos.h"

//#import "NSObject+SBJSON.h"
//
//#import "ETUrlEngine.h"
#import "ASIFormDataRequest.h"
//#import "ETMyShopEditDateSource.h"
//#import "LoginViewController.h"
#import "HTTPImageView.h"

#import "smPhotoItemView.h"
#import "UpLoadImageModel.h"

//#import "ETUploadMyShopDateView.h"
//#import "ETUtilHelper.h"
//#import "ETViewUtil.h"


#define __MAX_TEXT_FIELD_LENGTH__           100

#define _ACTIONSHEET_PHOTOCHOOSE_           7001
#define _ACTIONSHEET_ADDRESSGET_            7002

#define _ACTIONTAG_NONE_                    7030
#define _ACTIONTAG_TIME_SET_PICKER_         7031
#define _ACTIONTAG_SHOP_INFO_TEXTFIELD_     7032
#define _ACTIONTAG_SHOP_ADDRESS_TEXTFIELD_  7033
#define _ACTIONTAG_SHOP_TRAFIC_TEXTFIELD_   7034
#define _ACTIONTAG_SHOP_TELE_TEXTFIELD_     7035



@interface smPhotoEditController()<UIScrollViewDelegate,GetPhotosDelegate,UIActionSheetDelegate,ASIHTTPRequestDelegate,UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIPickerViewDataSource,UIPickerViewDelegate,UpLoadImageDelegate,AddShopPhotoDelegate,UITextViewDelegate> {

    int actionTag;
    
    BOOL isSaveAndClose;
    
    BOOL isShopInfoChanged;
}


-(void) initEditMyPhotoView;
-(void) cheekGpsPositionAndAddressName;
-(void) getMyShopInfo;
-(void) saveMyShop;
-(void) upLoadAllImages;

-(void) hideAllInputView;

@property (nonatomic, strong) UITableView* shopTableView;
@property (nonatomic, strong) UIScrollView* chooseMyShopPhotoScrollView;
@property (nonatomic, strong) NSMutableArray* myShopPhontos;
@property (nonatomic, strong) GetPhotos* getPhoto;
//@property (nonatomic, strong) ETMyShopEditDateSource* myShopEditDateSource;
@property (nonatomic, strong) ETMyShopItem* myShopItem;

@property (nonatomic, strong) UITextField* myShopAddressTextField;
@property (nonatomic, strong) UITextField* myShopInfoTextField;
@property (nonatomic, strong) UITextView* myShopTraficTextView;
//@property (nonatomic, strong) UITextField* myShopTeleNumTextField;
@property (nonatomic, strong) UITextField* myShopPhoneNumTextField;
@property (nonatomic, strong) UIButton* myShopTimeTextButton;

@property (nonatomic, strong) UIPickerView* myShopTimeSetPickView;

//@property (nonatomic, strong) ETUploadMyShopDateView* upLoadShopDateView;

@property (nonatomic, strong) UIView* footView;

@property (nonatomic, strong) UILabel* myShopDescriptionFontCountLabel;
@property (nonatomic, strong) UILabel* myShopAddressFontCountLabel;
@property (nonatomic, strong) UILabel* myShopTracficFontCountLabel;


@property (nonatomic, strong) NSString* myShopDescription;
@property (nonatomic, strong) NSString* myShopAddress;
@property (nonatomic, strong) NSString* myShopTracfic;
@property (nonatomic, strong) NSString* myShopTele;

@property (nonatomic, strong) NSString* myShopLat;
@property (nonatomic, strong) NSString* myShopLon;
@property (nonatomic, strong) NSString* myShopOpenTime;
@property (nonatomic, strong) NSString* myShopCloseTime;

@end

@implementation smPhotoEditController

@synthesize shopTableView;
@synthesize chooseMyShopPhotoScrollView;
@synthesize myShopPhontos;
@synthesize getPhoto;
//@synthesize myShopEditDateSource;
@synthesize myShopItem;

@synthesize myShopAddressTextField = _myShopAddressTextField;
@synthesize myShopInfoTextField = _myShopInfoTextField;
@synthesize myShopTraficTextView = _myShopTraficTextView;
//@synthesize myShopTeleNumTextField;
@synthesize myShopPhoneNumTextField = _myShopPhoneNumTextField;
@synthesize myShopTimeTextButton = _myShopTimeTextButton;
@synthesize myShopTimeSetPickView = _myShopTimeSetPickView;
//@synthesize upLoadShopDateView = _upLoadShopDateView;
@synthesize footView = _footView;

@synthesize myShopDescriptionFontCountLabel = _myShopDescriptionFontCountLabel;
@synthesize myShopAddressFontCountLabel = _myShopAddressFontCountLabel;
@synthesize myShopTracficFontCountLabel = _myShopTracficFontCountLabel;

@synthesize myShopDescription = _myShopDescription;
@synthesize myShopAddress = _myShopAddress;
@synthesize myShopTracfic = _myShopTracfic;
@synthesize myShopTele = _myShopTele;

@synthesize myShopLat = _myShopLat;
@synthesize myShopLon = _myShopLon;
@synthesize myShopOpenTime = _myShopOpenTime;
@synthesize myShopCloseTime = _myShopCloseTime;

@synthesize upDateShopdelegate = _upDateShopdelegate;


- (id)initWithMyShopItem:(ETMyShopItem*) shopItem {
    self = [super init];
    self.myShopItem = shopItem;	
    
//    self.myShopDescription = self.myShopItem.description;
//    self.myShopAddress = self.myShopItem.address;
//    self.myShopTracfic = self.myShopItem.trafficInfo;
//    self.myShopTele = self.myShopItem.tel;
//    
//    self.myShopLat = self.myShopItem.latitude;
//    self.myShopLon = self.myShopItem.longitude;
//    self.myShopOpenTime = self.myShopItem.openTime;
//    self.myShopCloseTime = self.myShopItem.closeTime;

    actionTag = _ACTIONTAG_NONE_;
	return self;
}


-(void) loadView {
    
    [super loadView];
    
    self.title = @"编辑店铺";
    isSaveAndClose = NO;
    isShopInfoChanged = NO;
    
//    self.navigationItem.rightBarButtonItem = [UIViewController getUIBarButtonItemWithText:@"保存" Target:self action:@selector(saveMyShop)];
    
//    [self.view setBackgroundColor:[EtaoBaseConfigForUX getBackGrayColor]];
    
    self.shopTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    [self.shopTableView setAutoresizesSubviews:YES];
    [self.shopTableView setDelegate:self];
    [self.shopTableView setDataSource:self];
    [self.shopTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.shopTableView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:self.shopTableView];
    
    [self initEditMyPhotoView];
    
    //获取GPS和城市名称
    //[self cheekGpsPositionAndAddressName];
}


-(void) viewDidLoad {

    [super viewDidLoad];
    
    [self getMyShopInfo];
}


- (void)viewWillDisappear:(BOOL)animated { 
    
    [super viewWillDisappear:animated];

}


-(void) initEditMyPhotoView {
    
    self.chooseMyShopPhotoScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 256)];
    [self.chooseMyShopPhotoScrollView setContentSize:CGSizeMake(246*5+10, 256)];
    [self.chooseMyShopPhotoScrollView setShowsHorizontalScrollIndicator:NO];
    [self.chooseMyShopPhotoScrollView setShowsVerticalScrollIndicator:NO];
    [self.chooseMyShopPhotoScrollView setScrollEnabled:YES];
    [self.chooseMyShopPhotoScrollView setBackgroundColor:[UIColor clearColor]];
    
    self.myShopPhontos = [[NSMutableArray alloc] init];
    
    for (int i=0; i<5; i++) {
        
        smPhotoItemView* tempImg = [[smPhotoItemView alloc] initWithFrame:CGRectMake(246*i+10, 10, 236, 236)];
        [tempImg setShopDefaultImage: [UIImage imageNamed:@"no_picture_80x80.png"]];
        
        [self.myShopPhontos addObject:tempImg];
        
        [tempImg setAddShopimgDelegate:self];
        [tempImg setUploadimgDelegate:self];
        
        tempImg.tag = i;
        
        [self.chooseMyShopPhotoScrollView addSubview:tempImg];
    }
    
    //Set店铺图片
    NSString* otherAllImgStr = @"";
    
    NSLog(otherAllImgStr,nil);
    
    if (otherAllImgStr == nil) {
        return;
    }
    
    NSArray* tempOtherImgArray = [otherAllImgStr componentsSeparatedByString:@","];
    
    if (tempOtherImgArray == nil) {
        return;
    }
    
    int TempIndex = 0;
    
    for (NSString* otherImgStr in tempOtherImgArray) {
        if (TempIndex > 4) {
            return;
        }
        
        [[self.myShopPhontos objectAtIndex:TempIndex] setmyShopHttpImgUrl:otherImgStr];
        TempIndex++;
    }
}


-(void) getMyShopInfo {
//    if (self.myShopEditDateSource == nil) {
//        self.myShopEditDateSource = [[ETMyShopEditDateSource alloc] init];
//    }
//    
//    [self.myShopEditDateSource setDateSourceDelegate:self];
}


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex == actionSheet.cancelButtonIndex) {
        return;   
    }
    
    //选择照片
    if (YES) {//actionSheet.tag == _ACTIONSHEET_PHOTOCHOOSE_) {
        
        self.getPhoto = [[GetPhotos alloc] init];
        [self.getPhoto initWithController:self];
        self.getPhoto.tag = actionSheet.tag;
        [self.getPhoto setDelegate:self];
        
        if (buttonIndex == actionSheet.destructiveButtonIndex) {
            [self.getPhoto getPhotosFromCamera];        
        } else if (buttonIndex == actionSheet.firstOtherButtonIndex) {
            [self.getPhoto getPhotosFromPhotoLibiary];
        }
    }
    
    //地址切换
//    else if (actionSheet.tag == _ACTIONSHEET_ADDRESSGET_) {
//        if (buttonIndex == actionSheet.firstOtherButtonIndex) {
//            [self.myShopAddressLabel setText:[self.locationDateSource currentPosition]];
//        }
//    }
    
}


- (void) addShopPhoto:(id) sel {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"亲，请选择照片来源"
															 delegate:self
                                                    cancelButtonTitle:@"取消，不选了"
                                               destructiveButtonTitle:@"照相机拍照"
                                                    otherButtonTitles:@"从相册选取",nil];
	actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    //actionSheet.tag = [(ETShopPhotoItemView*)sel tag];//_ACTIONSHEET_PHOTOCHOOSE_;
 	[actionSheet showInView:self.view];
}


-(void) upLoadAllImages {

    for (smPhotoItemView* itemView in self.myShopPhontos) {
        [itemView upLoadImageToSever];
    }
}


-(void) setMyShopDate {
    
//    if (self.myShopItem == nil) {
//        self.myShopItem = [[ETMyShopItem alloc] init];
//    }
//    
//    //新店开张
//    if (self.myShopItem.shopId != nil) {
//        [self.myShopItem setActionType:@"2"];        
//    }
//    else {
//        [self.myShopItem setActionType:@"1"];
//    }
//    
//    [self.myShopItem setUserId:[TOP userId]];
//    [self.myShopItem setNick:[TOP userNick]];
//    
//    [self.myShopItem setDescription: self.myShopDescription];
//    [self.myShopItem setTrafficInfo: self.myShopTracfic];
//    [self.myShopItem setTel: self.myShopTele];
//    
//    [self.myShopItem setLatitude: self.myShopLat];
//    [self.myShopItem setLongitude: self.myShopLon];
//    [self.myShopItem setOpenTime: self.myShopOpenTime];
//    [self.myShopItem setCloseTime: self.myShopCloseTime];
//    [self.myShopItem setAddress: self.myShopAddress];
//    
    
    NSMutableString* tempOthPicUrl = [[NSMutableString alloc] init];
    
    //更新主图，仔细看，别随便乱改,为第一张图
//    [self.myShopItem setMainPic:nil];
//    
//    for (ETShopPhotoItemView* itemView in self.myShopPhontos) {
//        if ( [itemView getImgViewShortName] != nil ) {
//            
//            if ([tempOthPicUrl length] > 4) {
//                [tempOthPicUrl appendString:@","];
//            }
//            
//            if (self.myShopItem.mainPic == nil) {
//                [self.myShopItem setMainPic:[itemView getImgViewShortName]];
//            }
//            
//            [tempOthPicUrl appendString:[itemView getImgViewShortName]];
//        }
//    }
//    
//    [self.myShopItem setOthPic:tempOthPicUrl]; 
    
    NSLog(tempOthPicUrl,nil);

}


//-(void) initUpLoadShopDateView {
//    
//    if (self.upLoadShopDateView == nil) {
//        self.upLoadShopDateView = [[ETUploadMyShopDateView alloc] initWithFrame:CGRectMake(0, 100, 320, 400)];
//        [self.view addSubview:self.upLoadShopDateView];
//    }
//    else {
//        [self.upLoadShopDateView setHidden:NO];
//    }
//}


-(void) upLoadAllChangedImages {
    
    for (smPhotoItemView* itemView in self.myShopPhontos) {
        if (itemView.isUpLoadFailed == NO) {
            
            if ([itemView isDefaultImage] == NO && [itemView isChangedImage] == YES) {
                if (itemView.isUpLoadSuccess == NO) {
                    return;
                }
            }            
        }
    }
    
    //[self.upLoadShopDateView setDateUploadProgress:@"保存数据中......"];
    //上传数据
    [self setMyShopDate];
    
//    self.myShopEditDateSource = [[ETMyShopEditDateSource alloc] init];
//    [self.myShopEditDateSource setDateSourceDelegate:self];
//    [self.myShopEditDateSource saveMyShopDate:self.myShopItem];
}


-(bool) isNoShopPhotos {

    for (smPhotoItemView* itemView in self.myShopPhontos) {
        if (itemView.isUpLoadFailed == NO) {

            if ([itemView isDefaultImage] == NO) {
                return NO;
            }
        }
    }

    return YES;
}


-(void) saveMyShop {
    
    [self hideAllInputView];
    
    //如果没GPS，无法上传
    //临时做法
    if (self.myShopLat == nil || self.myShopLon == nil || [self.myShopLat isEqualToString:@""] || [self.myShopLon isEqualToString:@""]) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存店铺失败" message:@"请先定位，得到GPS位置后，再保存店铺！" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        //alert.delegate  = self;
        [alert show];
        
        isSaveAndClose = NO;
        return;
    }else if (self.myShopAddress == nil || [self.myShopAddress isEqualToString: @""]) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存店铺失败" message:@"请先输入地址后，再保存店铺！" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        //alert.delegate  = self;
        [alert show];
        
        isSaveAndClose = NO;
        return;
    }else if (self.myShopTele == nil || [self.myShopTele isEqualToString: @""]) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存店铺失败" message:@"请先输入移动电话，再保存店铺！" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        //alert.delegate  = self;
        [alert show];
        
        isSaveAndClose = NO;
        return;
    }
    
    if ([self isNoShopPhotos] == YES) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存店铺失败" message:@"请至少排一张店铺照片，再保存店铺！" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        //alert.delegate  = self;
        [alert show];
        
        isSaveAndClose = NO;
        return;
    }
    
    
    //判断是不是手机格式
//    if ([ETUtilHelper isMobileNumber: self.myShopTele] == NO) {
//            
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存店铺失败" message:@"请输入正确的手机格式！" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
//        //alert.delegate  = self;
//        [alert show];
//        
//        isSaveAndClose = NO;
//        return;
//    }
    
    //上传界面
    //[self initUpLoadShopDateView];
    
//    int tempIndex = 0;
//    for (ETShopPhotoItemView* itemView in self.myShopPhontos) {
//        if ([itemView isChangedImage] && itemView.isUpLoadSuccess == NO) {
//            [self.upLoadShopDateView setImageUploadProgress:tempIndex infoStr:@"正在上传中..."];
//        }
//        else {
//            [self.upLoadShopDateView setImageUploadProgress:tempIndex infoStr:@"无需更新"];
//        }
//        tempIndex++;
//    }
//
//    
//    //上传图片
//    [self upLoadImages:nil];
//    for (ETShopPhotoItemView* itemView in self.myShopPhontos) {
//        if (itemView.isUpLoadSuccess == YES) {
//            //itemView.isChanged = NO;
//            [self.upLoadShopDateView setImageUploadProgress:itemView.tag infoStr:@"无需上传"];
//        }
//    }
    
    //上传数据
    [self upLoadAllImages];
    
    [self upLoadAllChangedImages];
    
    [self showMbprogress];
}


- (void) positionMyShop:(UIButton*) button {
    [self cheekGpsPositionAndAddressName];
}


- (void) changeMyShopOnTime:(UIButton*) button {
    
    NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
    
    actionTag = _ACTIONTAG_TIME_SET_PICKER_;
    [self.shopTableView beginUpdates];
    [self.shopTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    [self.shopTableView endUpdates];      
}


-(void) timeSetPickerBeenHidden {
    [self.myShopTimeSetPickView setHidden:YES];
}


- (void) getPhotoFinished:(UIImage *)image {
    [[self.myShopPhontos objectAtIndex:getPhoto.tag] setShopNewImage:image];
}


-(void) hideAllInputView {

    [self.myShopInfoTextField resignFirstResponder];
    [self.myShopAddressTextField resignFirstResponder];
    [self.myShopTraficTextView resignFirstResponder];
    [self.myShopPhoneNumTextField resignFirstResponder];
    
    if(self.myShopTimeSetPickView != nil && [self.myShopTimeSetPickView isHidden] == NO) {
        //动画
        
        [UIView beginAnimations:nil context:NULL];
        
        [self.myShopTimeSetPickView setFrame:CGRectMake(0, 480, 320, 160)];
        
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.3];
        [UIView setAnimationDidStopSelector:@selector(timeSetPickerBeenHidden)];
        [UIView commitAnimations];
    }
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    [self hideAllInputView];
}


- (void)requestFinished:(ASIHTTPRequest *)request {
    
    NSData *data = [NSData dataWithData:[request responseData]]; 	
    
    NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingUTF8);
    NSString* temPStr = [[NSString alloc] initWithData:data encoding:enc]; 
    
    NSLog(temPStr,nil);
    
    //保存成功退出
    if (isSaveAndClose == YES) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"上传成功" message:[NSString stringWithFormat:temPStr] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    //alert.delegate  = self;
    [alert show];
}


- (void)requestFailed:(ASIHTTPRequest *)request {
    
    NSData *data = [NSData dataWithData:[request responseData]]; 	
    
    NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingUTF8);
    NSString* temPStr = [[NSString alloc] initWithData:data encoding:enc]; 
    
    NSLog(temPStr,nil);
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"上传失败" message:[NSString stringWithFormat:temPStr] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    //alert.delegate  = self;
    [alert show];
}


- (void) ModelRequestDidFinish:(NSObject *)obj {
//    
//    if([obj isKindOfClass:[ETMyShopEditDateSource class]] == YES) {
//
//        [self hideMbProgress];
//        
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存成功" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
//        //alert.delegate  = self;
//        [alert show];
//
//        
//        //[self.upLoadShopDateView setDateUploadProgress :@"数据保存完成了！！！"];  
//        
//        //设置更新
//        [self.upDateShopdelegate setNeedUpdate];
//        
//        //保存成功退出
//        if (isSaveAndClose == YES) {
//            [self.navigationController popViewControllerAnimated:YES];
//            return;
//        }
//    }
}


- (void) ModelRequestDidFailed:(NSObject *)obj {
//
//    [self hideMbProgress];
//    if([obj isKindOfClass:[ETMyShopEditDateSource class]] == YES) {
//        
//        NSString* tempStr = ((ETMyShopEditDateSource*)obj).successReturnStr;
//        
//        NSDictionary *jsonValue = [tempStr JSONValue]; 
//        
//        NSArray* retArray = [jsonValue objectForKey:@"ret"];
//        
//        if ([retArray count] > 0) {
//            if ([([[jsonValue objectForKey:@"ret"] objectAtIndex:0]) isEqualToString:@"ERR_SID_INVALID::SESSION过期"]  ) {
//                if (self.loginViewController == nil) {
//                    _loginViewController = [[LoginViewController alloc]init];
//                    _loginViewController.delegate = self;
//                }
//                ETUINavigationController* loginNav = [[ETUINavigationController alloc]initWithRootViewController:_loginViewController];
//                loginNav.hidesBottomBarWhenPushed = YES;
//                [self presentModalViewController:loginNav animated:YES];
//                return;
//            }
//            
//            //菊花啊。。。玄伟写的接口有问题。。。Session过期，也提示非法请求。。。爆了Y的菊花。
//            else if ([([[jsonValue objectForKey:@"ret"] objectAtIndex:0]) isEqualToString:@"ERRCODE_AUTH_REJECT::非法的请求"]){
//                if (self.loginViewController == nil) {
//                    _loginViewController = [[LoginViewController alloc]init];
//                    _loginViewController.delegate = self;
//                }
//                ETUINavigationController* loginNav = [[ETUINavigationController alloc]initWithRootViewController:_loginViewController];
//                loginNav.hidesBottomBarWhenPushed = YES;
//                [self presentModalViewController:loginNav animated:YES];
//                return;
//            }
//            
//        }
//    }
//    
//    if([obj isKindOfClass:[ETMyShopEditDateSource class]] == YES) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存失败" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
//    //alert.delegate  = self;
//        [alert show];
//    }
}


- (UITableViewCell*) editPhotosMyShopForTableView {
    static NSString *CellIdentifier = @"EditPhotosForMyShop";
    
    UITableViewCell *editShopMyShopCell = [self.shopTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (editShopMyShopCell == nil) 
        editShopMyShopCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
    for (UIView *v in [editShopMyShopCell subviews]) {
        if ([v isKindOfClass:[UILabel class]] | [v isKindOfClass:[UIImageView class]]
            | [v isKindOfClass:[UIButton class]] | [v isKindOfClass:[HTTPImageView class]]) {
            [v removeFromSuperview];
        }
    }
	
    //点击背景颜色不变
    editShopMyShopCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [editShopMyShopCell addSubview:self.chooseMyShopPhotoScrollView];
    return editShopMyShopCell;
}


- (UITableViewCell*) editTimesMyShopForTableView {
    static NSString *CellIdentifier = @"EditTimesForMyShop";
    
    UITableViewCell *editShopMyShopCell = [self.shopTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (editShopMyShopCell == nil) 
        editShopMyShopCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
    for (UIView *v in [editShopMyShopCell subviews]) {
        if ([v isKindOfClass:[UILabel class]] | [v isKindOfClass:[UIImageView class]]
            | [v isKindOfClass:[UIButton class]] | [v isKindOfClass:[HTTPImageView class]]) {
            [v removeFromSuperview];
        }
    }
	
    //点击背景颜色不变
    editShopMyShopCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //[editShopMyShopCell addSubview:self.myShopTimeSetPickView];
    return editShopMyShopCell;
}


- (UITableViewCell*) editTeleMyShopForTableView {
    static NSString *CellIdentifier = @"EditTeleForMyShop";
    
    UITableViewCell *editTeleMyShopCell = [self.shopTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (editTeleMyShopCell == nil) 
        editTeleMyShopCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
    for (UIView *v in [editTeleMyShopCell subviews]) {
        if ([v isKindOfClass:[UILabel class]] | [v isKindOfClass:[UIImageView class]]
            | [v isKindOfClass:[UIButton class]] | [v isKindOfClass:[HTTPImageView class]]) {
            [v removeFromSuperview];
        }
    }
	
    //点击背景颜色不变
    editTeleMyShopCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView* infoBackImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shopTel.png"]];
    [infoBackImgView setFrame:CGRectMake(10, 8, 300, 38)];
    [editTeleMyShopCell addSubview:infoBackImgView];
    
    UILabel* tempLaber = [[UILabel alloc] initWithFrame:CGRectMake(20, 17, 60, 20)];
    [tempLaber setBackgroundColor:[UIColor clearColor]];
    [tempLaber setTextColor:[UIColor colorWithRed:51.0/255 green:51.0/255 blue:51.0/255 alpha:1.0]];
    tempLaber.font = [UIFont systemFontOfSize:12]; 
    [tempLaber setText:@"移动电话:"];
    [editTeleMyShopCell addSubview:tempLaber];
    
    if (self.myShopPhoneNumTextField == nil) {
        self.myShopPhoneNumTextField = [[UITextField alloc] initWithFrame:CGRectMake(75, 20, 300, 20)];
        [editTeleMyShopCell addSubview:self.myShopPhoneNumTextField];
        [self.myShopPhoneNumTextField setDelegate:self];
    }
    
    [self.myShopPhoneNumTextField addTarget:self action:@selector(limitTextlength:) forControlEvents:UIControlEventEditingChanged];
    [self.myShopPhoneNumTextField setPlaceholder:@"电话(选填)"];
    self.myShopPhoneNumTextField.font = [UIFont systemFontOfSize:12];
    self.myShopPhoneNumTextField.borderStyle = UITextBorderStyleNone;//设置文本框边框风格
    [self.myShopPhoneNumTextField setDelegate:self];
    [self.myShopPhoneNumTextField setKeyboardType:UIKeyboardTypePhonePad];
    
    if (self.myShopTele != nil) {
        self.myShopPhoneNumTextField.text = self.myShopTele;
    }
    
    [editTeleMyShopCell addSubview:self.myShopPhoneNumTextField];
    
    return editTeleMyShopCell;
}


- (UITableViewCell*) editTraficMyShopForTableView {
    static NSString *CellIdentifier = @"EditTraficForMyShop";
    
    UITableViewCell *editTraficMyShopCell = [self.shopTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (editTraficMyShopCell == nil) 
        editTraficMyShopCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
    for (UIView *v in [editTraficMyShopCell subviews]) {
        if ([v isKindOfClass:[UILabel class]] | [v isKindOfClass:[UIImageView class]]
            | [v isKindOfClass:[UIButton class]] | [v isKindOfClass:[HTTPImageView class]]) {
            [v removeFromSuperview];
        }
    }
	
    //点击背景颜色不变
    editTraficMyShopCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView* infoBackImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shopTracfic.png"]];
    [infoBackImgView setFrame:CGRectMake(10, 0, 300, 78)];
    [editTraficMyShopCell addSubview:infoBackImgView];
    
    UILabel* tempLaber = [[UILabel alloc] initWithFrame:CGRectMake(20, 7, 60, 20)];
    [tempLaber setBackgroundColor:[UIColor clearColor]];
    [tempLaber setTextColor:[UIColor colorWithRed:51.0/255 green:51.0/255 blue:51.0/255 alpha:1.0]];
    tempLaber.font = [UIFont systemFontOfSize:13]; 
    [tempLaber setText:@"交通信息:"];
    [editTraficMyShopCell addSubview:tempLaber];
    
    if (self.myShopTraficTextView == nil) {
        self.myShopTraficTextView = [[UITextView alloc] initWithFrame:CGRectMake(75, 1, 225, 90)];
        [editTraficMyShopCell addSubview:self.myShopTraficTextView];
    }

    //[self.myShopTraficTextView addTarget:self action:@selector(limitTextlength:) forControlEvents:UIControlEventEditingChanged];
    [self.myShopTraficTextView setScrollEnabled:NO];
    [self.myShopTraficTextView setScrollsToTop:NO];
    [self.myShopTraficTextView setPagingEnabled:NO];
    [self.myShopTraficTextView setBackgroundColor:[UIColor clearColor]];
    self.myShopTraficTextView.editable = YES;
    self.myShopTraficTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度  

    [self.myShopTraficTextView setBackgroundColor:[UIColor clearColor]];
    [self.myShopTraficTextView setTextColor:[UIColor colorWithRed:51.0/255 green:51.0/255 blue:51.0/255 alpha:1.0]];
    
    [self.myShopTraficTextView setDelegate:self];
    [self.myShopTraficTextView setContentMode:UIViewContentModeTopLeft];
    [self.myShopTraficTextView setText:@"交通信息(选填)请概要说明周边显著建筑"];

    self.myShopTraficTextView.font = [UIFont systemFontOfSize:13];
    
    if (self.myShopTracfic != nil) {
        self.myShopTraficTextView.text = self.myShopTracfic;
    }
    
    [editTraficMyShopCell addSubview:self.myShopTraficTextView];
    
    self.myShopTracficFontCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 55, 40, 20)];
    [self.myShopTracficFontCountLabel setFont: [UIFont systemFontOfSize:13]];
    [self.myShopTracficFontCountLabel setBackgroundColor: [UIColor clearColor]];
    [self.myShopTracficFontCountLabel setText: [NSString stringWithFormat: @"%d字",[self.myShopTracfic length]]];
    [editTraficMyShopCell addSubview: self.myShopTracficFontCountLabel];
    
    return editTraficMyShopCell;
}


- (UITableViewCell*) saveMyShopForTableView {
    
    static NSString *CellIdentifier = @"saveShopForMyShop";
    
    UITableViewCell *saveShopMyShopCell = [self.shopTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (saveShopMyShopCell == nil) 
        saveShopMyShopCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
    for (UIView *v in [saveShopMyShopCell subviews]) {
        if ([v isKindOfClass:[UILabel class]] | [v isKindOfClass:[UIImageView class]]
            | [v isKindOfClass:[UIButton class]] | [v isKindOfClass:[HTTPImageView class]]) {
            [v removeFromSuperview];
        }
    }
	
    //点击背景颜色不变
    saveShopMyShopCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //上传图片，
//    UIButton* tempButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//    [tempButton setFrame:CGRectMake(10, 5, 300, 30)];
//    [tempButton setTitle:@"（测试用，只上传图片）" forState:UIControlStateNormal];  
//    [tempButton addTarget:self action:@selector(upLoadImages:) forControlEvents:UIControlEventTouchUpInside];
//    [saveShopMyShopCell addSubview:tempButton];
//    
    //保存店铺，
    
    NSString* saveShopStr = @"保存店铺数据";
    
    UIImageView* imageShopSaveBtNorView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 38)];
    [imageShopSaveBtNorView setImage:[UIImage imageNamed:@"shopsaveNor.png"]];
    UILabel* tempShopSaveBtNorLabel = [[UILabel alloc] initWithFrame:imageShopSaveBtNorView.bounds];
    [tempShopSaveBtNorLabel setBackgroundColor:[UIColor clearColor]];
    [tempShopSaveBtNorLabel setText:saveShopStr];
    [tempShopSaveBtNorLabel setTextColor:[UIColor whiteColor]];
    tempShopSaveBtNorLabel.font = [UIFont systemFontOfSize:15];
    [tempShopSaveBtNorLabel setTextAlignment:UITextAlignmentCenter];
    [imageShopSaveBtNorView addSubview:tempShopSaveBtNorLabel];
    
    UIImageView* imageShopSaveBtFocView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 38)];
    [imageShopSaveBtFocView setImage:[UIImage imageNamed:@"shopsavefoc.png"]];
    UILabel* tempShopSaveBtFocLabel = [[UILabel alloc] initWithFrame:imageShopSaveBtFocView.bounds];
    [tempShopSaveBtFocLabel setBackgroundColor:[UIColor clearColor]];
    [tempShopSaveBtFocLabel setText:saveShopStr];
    [tempShopSaveBtFocLabel setTextColor:[UIColor whiteColor]];
    tempShopSaveBtFocLabel.font = [UIFont systemFontOfSize:15];
    [tempShopSaveBtFocLabel setTextAlignment:UITextAlignmentCenter];
    [imageShopSaveBtFocView addSubview:tempShopSaveBtFocLabel];

    UIButton* tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [tempButton setFrame:CGRectMake(10, 10, 300, 37)];
    [tempButton setTitle:@"保存店铺数据了！亲" forState:UIControlStateNormal];  
    [tempButton addTarget:self action:@selector(saveMyShop) forControlEvents:UIControlEventTouchUpInside];
    [saveShopMyShopCell addSubview:tempButton];
    
    return saveShopMyShopCell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 140;
        }
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            return 140;
        }
    }else if (indexPath.section == 2) {
        return 0;
//        if (indexPath.row == 0) {
//            if (self.myShopTimeSetPickView == nil) {
//                return 0;
//            }else if([self.myShopTimeSetPickView isHidden] == YES) {
//                return 0;
//            }
//            return self.myShopTimeSetPickView.bounds.size.height;
//        }
    }
    else if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            return self.chooseMyShopPhotoScrollView.bounds.size.height;
        }
    }else if (indexPath.section == 4) {
        if (indexPath.row == 0) {
            return 80;
        }
    }else if (indexPath.section == 5) {
        if (indexPath.row == 0) {
            return 50;
        }
    }else if (indexPath.section == 6) {
        if (indexPath.row == 0) {
            return 210;//80
        }
    }
    
    return 0;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 7;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 6) {
        return self.footView.bounds.size.height;
    }
    return 0;
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 6) {
        if (self.footView == nil) {
            self.footView = [[UIView alloc] initWithFrame:CGRectMake(0, 1, 1, 100)];
            [self.footView setHidden:YES];
        }
        return self.footView;
    }
    return nil;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else if (section == 1) {
        return 1;
    } else if (section == 2) {
        return 1;
    } else if (section == 3) {
        return 1;
    } else if (section == 4) {
        return 1;
    } else if (section == 5) {
        return 1;
    }else if (section == 6) {
        return 1;
    }
    
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 2) {
        return [self editTimesMyShopForTableView];
    }else if (indexPath.section == 3) {
        return [self editPhotosMyShopForTableView];
    }else if (indexPath.section == 4) {
        return [self editTraficMyShopForTableView];
    }else if (indexPath.section == 5) {
        return [self editTeleMyShopForTableView];
    }else if (indexPath.section == 6) {
        return [self saveMyShopForTableView];
    }
    
    return nil;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

//- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition
    
    if (tableView == self.shopTableView) {
//        [tableView beginUpdates];
//        [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
//        [tableView endUpdates];      
    }
}


- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    
    if (scrollView == self.shopTableView) {
        
        switch (actionTag) {
            case _ACTIONTAG_TIME_SET_PICKER_: {
                
                if (self.myShopTimeSetPickView == nil) {
                    self.myShopTimeSetPickView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 480, 320, 160)];
                    self.myShopTimeSetPickView.delegate = self;
                    [self.myShopTimeSetPickView setHidden:YES];
                    self.myShopTimeSetPickView.showsSelectionIndicator = YES;
                    [self.view addSubview:self.myShopTimeSetPickView];
                }

                if ([self.myShopTimeSetPickView isHidden] == YES) {
                    [self.myShopTimeSetPickView setHidden:NO];
                    
                    //动画
                    [UIView beginAnimations:nil context:NULL];
                    [self.myShopTimeSetPickView setFrame:CGRectMake(0, 210, 320, 160)];
                    
                    //设置营业时间
                    //- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;
                        
                    if (self.myShopOpenTime != nil) {
                        NSArray* tempArray = [self.myShopOpenTime componentsSeparatedByString:@":"];
                        
                        [self.myShopTimeSetPickView selectRow:[[tempArray objectAtIndex:0] intValue] inComponent:1 animated:NO];
                        
                        int tempInt = [[tempArray objectAtIndex:1] intValue];
                        
                        [self.myShopTimeSetPickView selectRow:tempInt/15%4 inComponent:2 animated:NO];
                    }
                    
                    if (self.myShopCloseTime != nil) {
                        NSArray* tempArray = [self.myShopCloseTime componentsSeparatedByString:@":"];
                        
                        [self.myShopTimeSetPickView selectRow:[[tempArray objectAtIndex:0] intValue] inComponent:4 animated:NO];
                        
                        int tempInt = [[tempArray objectAtIndex:1] intValue];
                        
                        [self.myShopTimeSetPickView selectRow:tempInt/15%4 inComponent:5 animated:NO];
                    }
                    
                    [UIView setAnimationDuration:0.3];
                    [UIView commitAnimations];
                }else {
                    
                    //动画
                    [UIView beginAnimations:nil context:NULL];
                    [self.myShopTimeSetPickView setFrame:CGRectMake(0, 480, 320, 160)];
                    
                    [UIView setAnimationDelegate:self];
                    [UIView setAnimationDuration:0.3];
                    [UIView setAnimationDidStopSelector:@selector(timeSetPickerBeenHidden)];
                    [UIView commitAnimations];
                }
                
                //展示时间编辑界面
                [self.shopTableView reloadData];
            }
                break;
                
            case _ACTIONTAG_SHOP_INFO_TEXTFIELD_: {
                [self.myShopInfoTextField becomeFirstResponder];
            }
                break;
                
            case _ACTIONTAG_SHOP_ADDRESS_TEXTFIELD_: {
                [self.myShopAddressTextField becomeFirstResponder];
            }
                break;
                
            case _ACTIONTAG_SHOP_TRAFIC_TEXTFIELD_: {
                [self.myShopTraficTextView becomeFirstResponder];
            }
                break;
                
            case _ACTIONTAG_SHOP_TELE_TEXTFIELD_: {
                [self.myShopPhoneNumTextField becomeFirstResponder];
            }
                break;
                
            default:
                break;
        }
    }
    
    actionTag = _ACTIONTAG_NONE_;
}


- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 6;
}


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

    if(component == 0 || component == 3) {
        return 1;
    } else if(component == 1 || component == 4) {
        return 24;
    } else if(component == 2 || component == 5) {
        return 4;
    }
    return 0;
}


- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    if (component == 0 || component == 3) {
        return 50;
    }
    return 40;
}


- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
    return 20;
}


- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return @" ";
}


- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f,0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)];
    
    [label setBackgroundColor:[UIColor clearColor]];
    
    if(component == 0) {
        label.text = @"开店";
    }else if(component == 3) {
        label.text = @"关店";
    }else if(component == 1 || component == 4) {
        label.text = [NSString stringWithFormat:@"%d",row];
    }else if(component == 2 || component == 5) {
        label.text = [NSString stringWithFormat:@"%d",row*15];
    }
    
    [label setTextAlignment:UITextAlignmentCenter];
    return label;
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    if (self.myShopTimeSetPickView != pickerView) {
        return;
    }
    
    int openTimeHour = [pickerView selectedRowInComponent:1];
    int openTimeMinute = [pickerView selectedRowInComponent:2]*15;
    int closeTimeHour = [pickerView selectedRowInComponent:4];
    int closeTimeMinute = [pickerView selectedRowInComponent:5]*15;

    if (openTimeHour > closeTimeHour) {
        closeTimeHour = openTimeHour;
        
        [pickerView selectRow:closeTimeHour inComponent:4 animated:YES];
    }
    else if (openTimeHour == closeTimeHour) {
        if(openTimeMinute > closeTimeMinute) {
            closeTimeMinute = openTimeMinute;
            [pickerView selectRow:closeTimeMinute/15%4 inComponent:5 animated:YES];
        }
    }
    
    self.myShopOpenTime = [NSString stringWithFormat:@"%d:%d",openTimeHour,openTimeMinute];            
    self.myShopCloseTime = [NSString stringWithFormat:@"%d:%d",closeTimeHour,closeTimeMinute];
    
    NSString* timeDisplay = [NSString stringWithFormat:@"营业时间为：%@~%@",self.myShopOpenTime, self.myShopCloseTime];
    
    [self.myShopTimeTextButton setTitle:timeDisplay forState:UIControlStateNormal];  
    
    [self.shopTableView reloadData];
}


- (void) postDataFinished:(id)sel {
    //ETShopPhotoItemView* tempItemView = (ETShopPhotoItemView*)sel;
    //[self.upLoadShopDateView setImageUploadProgress:tempItemView.tag infoStr:@"上传完成"];
    [self upLoadAllChangedImages];
}


- (void) postDataFailed:(id)sel {
    smPhotoItemView* tempItemView = (smPhotoItemView*)sel;
    
    NSString* tempStr = tempItemView.uploadImageDateSource.SuccessReturnStr;
//    
//    NSDictionary *jsonValue = [tempStr JSONValue]; 
//
//    //[self.upLoadShopDateView setImageUploadProgress:tempItemView.tag infoStr:@"上传失败"];
//   
//    [self hideMbProgress];
//   
//    NSArray* retArray = [jsonValue objectForKey:@"ret"];
//    
//    if ([retArray count] > 0) {
//        if ([([[jsonValue objectForKey:@"ret"] objectAtIndex:0]) isEqualToString:@"ERR_SID_INVALID::SESSION过期"]  ) {
//            if (self.loginViewController == nil) {
//                _loginViewController = [[LoginViewController alloc]init];
//                _loginViewController.delegate = self;
//            }
//            ETUINavigationController* loginNav = [[ETUINavigationController alloc]initWithRootViewController:_loginViewController];
//            loginNav.hidesBottomBarWhenPushed = YES;
//            loginNav.navigationBar.object4etao = [[EtaoBaseConfigForUX getNavBarView] getImage];
//            [self presentModalViewController:loginNav animated:YES];
//            return;
//        }
//        
//        //菊花啊。。。玄伟写的接口有问题。。。Session过期，也提示非法请求。。。爆了Y的菊花。
//        else if ([([[jsonValue objectForKey:@"ret"] objectAtIndex:0]) isEqualToString:@"ERRCODE_AUTH_REJECT::非法的请求"]){
//            if (self.loginViewController == nil) {
//                _loginViewController = [[LoginViewController alloc]init];
//                _loginViewController.delegate = self;
//            }
//            ETUINavigationController* loginNav = [[ETUINavigationController alloc]initWithRootViewController:_loginViewController];
//            loginNav.hidesBottomBarWhenPushed = YES;
//            loginNav.navigationBar.object4etao = [[EtaoBaseConfigForUX getNavBarView] getImage];
//
//            [self presentModalViewController:loginNav animated:YES];
//            return;
//        }
//
//    }
//        
    NSString* alertInfo = [NSString stringWithFormat:@"第%d张图片上传失败，重新上传，还是直接保存", tempItemView.tag];
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"图片上传" message: alertInfo delegate:self cancelButtonTitle:@"重新上传" otherButtonTitles:@"直接保存", nil];
    [alert show];
    
    return;
}


- (void) postDataProgress:(id)sel {
    
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    
    if (textField == self.myShopInfoTextField) {
        
        NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        
        actionTag = _ACTIONTAG_SHOP_INFO_TEXTFIELD_;
        [self.shopTableView beginUpdates];
        [self.shopTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        [self.shopTableView endUpdates];
        return YES;
    } else if (textField == self.myShopAddressTextField) {
        
        NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
        
        actionTag = _ACTIONTAG_SHOP_ADDRESS_TEXTFIELD_;
        [self.shopTableView beginUpdates];
        [self.shopTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        [self.shopTableView endUpdates];
        return YES;
    } else if (textField == self.myShopPhoneNumTextField) {
        
        NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:6];
        
        actionTag = _ACTIONTAG_SHOP_TELE_TEXTFIELD_;
        [self.shopTableView beginUpdates];
        [self.shopTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        [self.shopTableView endUpdates];
        return YES;
    }
    
    return NO;
}


- (void)textFieldDidEndEditing:(UITextField *)textField {
    [self.footView setHidden:YES];
        
    if (textField == self.myShopInfoTextField) {
        self.myShopDescription = self.myShopInfoTextField.text;
    } else if (textField == self.myShopAddressTextField) {
        self.myShopAddress = self.myShopAddressTextField.text;
    } else if (textField == self.myShopPhoneNumTextField) {
        self.myShopTele = self.myShopPhoneNumTextField.text;
    }
    
    //    myShopDescriptionFontCountLabel;
    //    myShopAddressFontCountLabel;
    //    myShopTracficFontCountLabel;
}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
    
    if (textView == self.myShopTraficTextView) {
        
        NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:5];
        
        actionTag = _ACTIONTAG_SHOP_TRAFIC_TEXTFIELD_;
        [self.shopTableView beginUpdates];
        [self.shopTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        [self.shopTableView endUpdates];
        return YES;
    } 
    
    return NO;
}


//- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
//    
//    if (textField == self.myShopInfoTextField) {
//        self.myShopDescription = self.myShopInfoTextField.text;
//    } else if (textField == self.myShopAddressTextField) {
//        self.myShopAddress = self.myShopAddressTextField.text;
//    } else if (textField == self.myShopPhoneNumTextField) {
//        self.myShopTele = self.myShopPhoneNumTextField.text;
//    }
//
////    //设置长度
////    NSMutableString *text = [textField.text mutableCopy];
////    [text replaceCharactersInRange:range withString:string];
////    
////    return [text length] <= 100;
////    
////    //if (textField.text.length >= __MAX_TEXT_FIELD_LENGTH__)
////        //return NO; // return NO to not change text
//    return YES;
//}


-(void)limitTextlength:(UITextField *)textField {
    
    int maxLength = __MAX_TEXT_FIELD_LENGTH__;
    
    if (self.myShopPhoneNumTextField == textField) {
        maxLength = 11;
        
        if ([textField.text length] > maxLength) {
            textField.text=[textField.text substringToIndex: maxLength];
        }
        
        self.myShopTele = textField.text;
    }
    
    else if (textField == self.myShopInfoTextField) {
        maxLength = 16;
        
        if ([textField.text length] > maxLength) {
            textField.text=[textField.text substringToIndex: maxLength];
        }
        
        self.myShopDescription = textField.text;
        [self.myShopDescriptionFontCountLabel setText: [NSString stringWithFormat: @"%d字",[self.myShopDescription length]]];
        
        if ([self.myShopDescription length] >= maxLength) {
            [self.myShopDescriptionFontCountLabel setTextColor:[UIColor redColor]];
        }else {
//            [self.myShopDescriptionFontCountLabel setTextColor:[EtaoBaseConfigForUX getTextLabellightGrayColor]];
        }

        return;
    }
    else if (textField == self.myShopAddressTextField) {
        maxLength = 50;
        
        if ([textField.text length] > maxLength) {
            textField.text=[textField.text substringToIndex: maxLength];
        }
        
        self.myShopAddress = textField.text;
        //[self.myShopDescriptionFontCountLabel setText: [NSString stringWithFormat: @"%d字",[self.myShopDescription length]]];
        
        return;
    }
}


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if (textView == self.myShopTraficTextView) {
        int maxLength = 60;
        
        if ([self.myShopTraficTextView.text length] > maxLength) {
            self.myShopTraficTextView.text=[self.myShopTraficTextView.text substringToIndex: maxLength];
        }
        
        self.myShopTracfic = self.myShopTraficTextView.text;
        [self.myShopTracficFontCountLabel setText: [NSString stringWithFormat: @"%d字",[self.myShopTracfic length]]];
        
        if ([self.myShopTracfic length] >= maxLength) {
            [self.myShopTracficFontCountLabel setTextColor:[UIColor redColor]];
        }else {
        }
    }

    return YES;
}


- (void)textViewDidEndEditing:(UITextView *)textView {
    
    if ([textView.text length] > __MAX_TEXT_FIELD_LENGTH__) {
        textView.text=[textView.text substringToIndex: __MAX_TEXT_FIELD_LENGTH__];
    }
    
    if (textView == self.myShopTraficTextView) {
        self.myShopTracfic = self.myShopTraficTextView.text;
    }    
}


-(BOOL) isMyShopInfoChanged {
    
    isShopInfoChanged = NO;
    
    for (smPhotoItemView* itemView in self.myShopPhontos) {
        if (itemView.isUpLoadFailed == NO) {
            
            if ([itemView isChangedImage] == YES) {
                if (itemView.isUpLoadSuccess == NO) {
                    isShopInfoChanged = YES;
                    return isShopInfoChanged;
                }
            }
            
        }
    }
    
    return isShopInfoChanged;
}


- (void) UIBarButtonItemBackClick:(UIBarButtonItem*)sender {   
    
    if ([self isMyShopInfoChanged] == YES) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存店铺" message:@"修改没有保存，退出将丢失所修改内容" delegate:self cancelButtonTitle:@"不保存" otherButtonTitles:@"保存并退出", nil];
        [alert show];
        return;
    }

    [self.navigationController popViewControllerAnimated:YES];
}


// Called when a button is clicked. The view will be automatically dismissed after this call returns
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if ([alertView.title isEqualToString:@"保存店铺"] == YES) {
        if ([alertView buttonTitleAtIndex:buttonIndex] == @"不保存") {
            isSaveAndClose = NO;
            [self.navigationController popViewControllerAnimated:YES];
            
        } else if ([alertView buttonTitleAtIndex:buttonIndex] == @"保存并退出") {
            isSaveAndClose = YES;
            [self saveMyShop];
        }
    }
    
    if ([alertView.title isEqualToString:@"图片上传"] == YES) {
        if ([alertView buttonTitleAtIndex:buttonIndex] == @"重新上传") {

            [self showMbprogress];

            [self upLoadAllImages];
            [self upLoadAllChangedImages];
            
        
        } else if ([alertView buttonTitleAtIndex:buttonIndex] == @"直接保存") {
           
            [self showMbprogress];
            
            [self setMyShopDate];
            
//            self.myShopEditDateSource = [[ETMyShopEditDateSource alloc] init];
//            [self.myShopEditDateSource setDateSourceDelegate:self];
//            [self.myShopEditDateSource saveMyShopDate:self.myShopItem];
        }
    }
}


//- (void) loginSuccessSelector:(NSObject *)obj
//{
//    [self.loginViewController dismissModalViewControllerAnimated:YES];
//    
//    
//    [self showMbprogress];
//    
//    [self saveMyShop];
//}
//
//- (void) loginCancelSelector:(NSObject *)obg
//{
//    [self.loginViewController dismissModalViewControllerAnimated:YES];
//    
//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存失败" message:@"登陆状态已经过期!" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//    [alert show];
//}

@end

